package com.nononsenseapps.feeder.ui.home

import android.view.ContextMenu
import android.view.MenuInflater
import android.view.View
import com.nononsenseapps.feeder.db.room.FAVORITE_FEED_ID
import com.nononsenseapps.feeder.db.room.READ_LATE_FEED_ID
import com.nononsenseapps.feeder.db.room.STORE_FEED_ID
import com.nononsenseapps.feeder.ui.R


class ReadLateHolder(onNavigationItemClickListener: OnNavigationItemClickListener, v: View) : AbstractFavoriteHolder(
    READ_LATE_FEED_ID,onNavigationItemClickListener,v), View.OnCreateContextMenuListener {

    init{
        v.setOnCreateContextMenuListener(this)
    }

    override fun onCreateContextMenu(menu: ContextMenu?, v: View?, menuInfo: ContextMenu.ContextMenuInfo?) {
        v?.context?.let { context ->
            if (menu != null) {
                MenuInflater(context).inflate(R.menu.contextmenu_feed_read_late, menu)

                menu.findItem(R.id.action_delete_all).setOnMenuItemClickListener {
                    onNavigationItemClickListener.clearFeedItem(READ_LATE_FEED_ID)
                    true
                }

                menu.findItem(R.id.action_delete_all).title = context.getString(R.string.action_clear_feed,item?.title)

                menu.findItem(R.id.action_move_to_store).setOnMenuItemClickListener {
                    onNavigationItemClickListener.moveFeedToFeed(READ_LATE_FEED_ID, STORE_FEED_ID)
                    true
                }

                menu.findItem(R.id.action_move_to_favorite).setOnMenuItemClickListener {
                    onNavigationItemClickListener.moveFeedToFeed(READ_LATE_FEED_ID, FAVORITE_FEED_ID)
                    true
                }
            }
        }
    }
}
